package com.jingbian.cppccbackend.controller.user;


import com.github.pagehelper.PageInfo;
import com.jingbian.cppccbackend.entity.News;
import com.jingbian.cppccbackend.entity.Result;
import com.jingbian.cppccbackend.entity.dto.NewsListDTO;
import com.jingbian.cppccbackend.service.user.INewsService;
import com.jingbian.cppccbackend.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 新闻表，用于存储新闻信息 前端控制器
 * </p>
 *
 * @author pum
 * @since 2025-03-03
 */
@RestController
@RequestMapping("/news")
public class NewsController {

  @Autowired
  private INewsService newsService;

  /**
   * 获取新闻列表
   * @param newsListDTO
   * @return
   */
  @PostMapping("/newsList")
  public Result<PageInfo<News>> newsList(@RequestBody NewsListDTO newsListDTO) {
     return ResultUtil.success(newsService.getNewList(newsListDTO));
  }

  /**
   * 查询新闻活动的详情
   * @param nid
   * @return
   */
  @GetMapping("/newsDetail/{nid}")
  public Result<News> newsDetail(@PathVariable Integer nid) {
    return ResultUtil.success(newsService.getNewsDetail(nid));
  }
}
